package edu.ucsd.cse110;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import edu.ucsd.cse110.model.Lift;

/**
 * Displays a list of lifts and return the LiftId of the lift.
 */
public class LiftSelectionActivity extends ListActivity {
	/**
	 * TODO: Need documentation.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		String[] lifts = getResources().getStringArray(R.array.lifts);
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, lifts));
	}

	/**
	 * TODO: Need documentation.
	 */
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		LocalDatabaseManager database = new LocalDatabaseManager(this);
		Lift item = database.getLiftByLiftId(position).get(0);
		database.close();

		Intent intent = new Intent();
		intent.putExtra("Id", item.getLiftId());
		intent.putExtra("liftString", item.getName());
		setResult(RESULT_OK, intent);
		finish();
	}
}